wx.cloud.init()
Page({

  data: {
    value: '',
    stu_number: " ",
    password: "",
    list: [],
    adminlist: [],
  },

  onLoad: function (options) {
    const db = wx.cloud.database()
    db.collection('data_stu').get({
      success: res => {
        this.list = res.data
      
      }
    })
    db.collection('data_user').get({
      success: res => {
        this.adminlist = res.data
        console.log(this.adminlist)
      }
    })

  },

  onReady: function () {

  },
  stuInput: function (e) {
    this.data.stu_number = e.detail
  },
  passwordInput: function (e) {
    this.data.password = e.detail
  },
  userlogin: function (e) {
    var that = this
    let newstu = that.data.stu_number
    let newpassword = that.data.password

    this.list.forEach(value => {
      if (newstu == value.stu_number && newpassword == value.password) {
        wx.showModal({
          title: '提示！',
          content: '登陆成功！',
          showCancel: false,
          success(res) {}
        })
        wx.navigateTo({
          url: '../index/index',
        })
      }
    });
  },

  adminlogin: function (e) {
    var that = this
    let newstu = that.data.stu_number
    let newpassword = that.data.password
    this.adminlist.forEach(value => {
      console.log(value)
      if (newstu == value.username && newpassword == value.password) {
        wx.showModal({
          title: '提示！',
          content: '登陆成功！',
          showCancel: false,
          success(res) {}
        })
        wx.navigateTo({
          url: '../librarymanagement/librarymanagement',
        })
      }
    });

  },



})